<?php
/**
 * 
 * Esta es el modelo de la Accion
 * @author Rosanna Paberli Jimenez Rosario
 *
 */
class AccionModel extends Model
{
	private $_nameTable = "US_Acciones";
	
	public function __construct()
	{
		parent::Model();
	}
	
	public function loadRegistro($modulo = false, $start = NULL, $offset = NULL, $sortname = NULL, $sortorder = NULL)
	{
		if ($modulo != false)  
		        $this->db->where('id_modulo', $modulo); 
		            
		if($offset != false){
               $this->db->limit($offset, $start);
         }
		      
		 if($sortname != false && $sortorder != false){
		        $this->db->order_by($sortname, $sortorder);
		 }
		 
		$query = $this->db->get($this->_nameTable);
		return $this->_getArrayFromQueryResult($query);
	}
	
	public function loadRegistroById($id)
	{
		$query = $this->db->get_where($this->_nameTable, array('id_accion' => $id));
		
		if($query->num_rows() == 0)
			return false;
		
			return new UsAccion($query->row());
		
	}
	
	public function getCount()
	{
		return count($this->loadRegistro());
	}
	
	private function _getArrayFromQueryResult($resurt)
	{
		if($resurt->num_rows() == 0){
			return false;
		}
		
		$registros = array();
		
		foreach($resurt->result() as $record){
			$registros[] = new UsAccion($record);
		}
		
		return $registros;
	}
	
	public function addRegistro($data)
	{
		 if($this->db->insert($this->_nameTable, $data)){
		 	return true;
		 }
		 	return false;
	}
	
	public function upDateRegistro($data, $id)
	{	
		if($this->db->update($this->_nameTable, $data, array('id_accion' => $id))){
			return true;
		}
			return false;
	}
	
	public function deleteRegistro($id)
	{
		if($this->db->delete($this->_nameTable, array("id_accion" => $id))){
		}
	}
}

class UsAccion
{
	private $_idAccion = 0;
	private $_detalleAccion = "";
	private $_idModulo = 0;
	
	public function __construct($dataObjeto)
	{
		$this->_idAccion = $dataObjeto->id_accion;
		$this->_detalleAccion = $dataObjeto->detalle_accion;
		$this->_idModulo = $dataObjeto->id_modulo;
	}
	
	public function getIdAccion()
	{
		return $this->_idAccion;
	}
	
	public function getDetalleAccion()
	{
		return $this->_detalleAccion;
	}
	
	public function getIdModulo()
	{
		return $this->_idModulo;
	}
	
}